<template>
  <div>
    <van-datetime-picker v-model="currentDate" type="date" title="选择年月日" :min-date="minDate" :max-date="maxDate"
      @cancel="$emit('close-popup')" @confirm="saveBirthday" />
  </div>
</template>

<script>
import { absoluteDate } from '@/filters'
import { editUserInfo } from '@/api/user.js'
export default {
  name: 'birthday',
  data () {
    return {
      currentDate: new Date(this.value),
      minDate: new Date(1900, 1, 1),
      maxDate: new Date()
    }
  },
  props: {
    value: {
      type: String,
      required: true
    }
  },
  methods: {
    async saveBirthday (val) {
      // 自定义加载图标
      const date = absoluteDate(val, 'YYYY-MM-DD')
      console.log(date)
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true,
        duration: 0
      })
      try {
        await editUserInfo({
          birthday: date
        })
        this.$toast.success('修改生日成功')
        this.$emit('close-popup')
        this.$emit('input', date)
      } catch (err) {
        this.$toast.fail('修改生日失败')
      }
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  created () { },
  mounted () { }
}
</script>

<style scoped lang='less'>
</style>
